package com.atguigu.gmall.search.vo;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonIgnoreType;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

//项目经理+产品+前端+后端
@Data
@Document(indexName = "goods" , shards = 3 , replicas = 2)
@JsonIgnoreProperties(value = "_class")
@ApiModel("搜索页数据模型")
public class Goods {
    //1、sku数据
    @Id
    private Long skuId;
    @Field(type = FieldType.Keyword , index = false)
    private String defaultImage;
    @Field(type = FieldType.Double)
    private BigDecimal price;
    @Field(type = FieldType.Text , analyzer = "ik_max_word")
    private String title;
    @Field(type = FieldType.Keyword )
    private String subtitile;
    //WMS:=======TODO
    //2、是否有货
    @Field(type = FieldType.Boolean)
    private Boolean store = false;
    //3、排序字段
    @Field(type = FieldType.Long)
    private Long sales = 0L;

    // java中的时间日期格式和 es的不一样
    @Field(type = FieldType.Date ,format = DateFormat.date)
    private Date createTime;

    //4、检索属性：有多个，来自于两张表 TODO
    // 原理： 每个SearchAttrValue对象都会隐式 生成一个新的文档
    // 以后查询时 检索条件 会匹配一个个的文档   而不是到整个集合列表中全部匹配
    @Field(type = FieldType.Nested)//使用Object会导致数据扁平化
    private List<SearchAttrValue> searchAttrs;

    //5、分类
    @Field(type = FieldType.Long)
    private Long categoryId;
    @Field(type = FieldType.Keyword)
    private String categoryName;
    //6、品牌
    @Field(type = FieldType.Long)
    private Long brandId;
    @Field(type = FieldType.Keyword)
    private String brandName;
    @Field(type = FieldType.Keyword , index = false)
    private String logo;


}
